package com.azure.bigstore.repository;

import com.azure.bigstore.entity.Product;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by liuhuaibin on 2018/1/23.
 */
public interface ProductRepository extends JpaRepository<Product,Long> {


    List<Product> findByCategoryAndTitleContaining(String category, String title);

    List<Product> findByTitleContaining(String title);

    List<Product> findByCategory(String category);

    @Query(value = "select * from t_product p where p.category=:ca order by num desc limit 8",nativeQuery = true)
    List<Product> findByCategorylimit8(@Param("ca") String category);

    @Query(value = "select * from t_product order by category", nativeQuery = true)
    List<Product> findAllOrderByCategory();

    @Query(value = "select * from t_product where id in (:ids)", nativeQuery = true)//(1,2,3,4)
    List<Product> findHotProducts(@Param("ids") List<Long> ids);
}
